﻿Public Class ViewParametrerGroupeCRT

    Private Sub BtSetGroupe_Click(sender As Object, e As Windows.RoutedEventArgs) Handles BtSetGroupe.Click

        Dim data As ViewModelParametrerGroupeCRT = DataContext

        Dim currentfilter = CType(CrtHistoDgrid.ItemsSource, DataView).RowFilter
        CType(CrtHistoDgrid.ItemsSource, DataView).RowFilter = ""
        For Each elt As DataRowView In CrtHistoDgrid.SelectedItems
            Dim eltrow As DataModel.PmtDataset.CorrespondanceCrtPmtRow = elt.Row
            eltrow.Groupe = data.GroupePmtActif
        Next
        CType(CrtHistoDgrid.ItemsSource, DataView).RowFilter = currentfilter

    End Sub

    Private Sub BtCreerCrtGroupePmt_Click(sender As Object, e As Windows.RoutedEventArgs) Handles BtCreerCrtGroupePmt.Click
        Dim inputdata As New ViewModelInputBox
        inputdata.Value = ""
        PMTModule.UIService.ShowMessage(inputdata, WindowTitle:="Entrez le  nom du groupe", ShowCloseButton:=False)
        Dim vm As ViewModelParametrerGroupeCRT = DataContext
        If Not String.IsNullOrEmpty(inputdata.Value.Trim().Replace(" ", "").ToUpper()) Then
            vm._ListeGroupesCrt.Add(inputdata.Value.Trim().Replace(" ", "").ToUpper())
        End If
    End Sub

    Private Sub BtUnSetGroupe_Click(sender As Object, e As Windows.RoutedEventArgs) Handles BtUnSetGroupe.Click

        Dim data As ViewModelParametrerGroupeCRT = DataContext

        Dim currentfilter = CType(PmtGroupeCrtDgrid.ItemsSource, DataView).RowFilter
        CType(PmtGroupeCrtDgrid.ItemsSource, DataView).RowFilter = ""

        For Each elt As DataRowView In PmtGroupeCrtDgrid.SelectedItems
            Dim eltrow As DataModel.PmtDataset.CorrespondanceCrtPmtRow = elt.Row
            eltrow.Groupe = ""
        Next

        CType(PmtGroupeCrtDgrid.ItemsSource, DataView).RowFilter = currentfilter

    End Sub

    Private Sub BtSupprimerCrtGroupePmt_Click(sender As Object, e As Windows.RoutedEventArgs) Handles BtSupprimerCrtGroupePmt.Click

        Dim data As ViewModelParametrerGroupeCRT = DataContext

        Dim currentfilter = CType(PmtGroupeCrtDgrid.ItemsSource, DataView).RowFilter
        CType(PmtGroupeCrtDgrid.ItemsSource, DataView).RowFilter = ""

        For Each elt As DataRowView In PmtGroupeCrtDgrid.ItemsSource
            Dim eltrow As DataModel.PmtDataset.CorrespondanceCrtPmtRow = elt.Row
            eltrow.Groupe = ""
        Next

        CType(PmtGroupeCrtDgrid.ItemsSource, DataView).RowFilter = currentfilter

        data.UpdateGroupeList()
    End Sub

    Private Sub TestHomogeneiteBt_Click(sender As Object, e As Windows.RoutedEventArgs) Handles TestHomogeneiteBt.Click
        Dim datamanager As New DataManager

        Dim data As ViewModelParametrerGroupeCRT = DataContext

        PMTModule.UIService.ShowMessage(datamanager.Test_Homogeneite_Groupe(data.GroupePmtActif))
    End Sub
End Class
